import { math, Vec2, Vec3 } from "cc";

/**
 * 二维工具类
 */
export class Vec2Util {
    /**获取两点连成的直线相对于水平线的角度，0-360 */
    static getAngle(x1: number, y1: number, x2: number, y2: number): number {
        var x = x1 - x2,
            y = y1 - y2;
        if (!x && !y) {
            return 0;
        }
        let tmp = Math.atan2(-y, -x);//范围是-3.x - 3.x;
        let angle = math.toDegree(tmp);
        angle = angle < 0 ? 360 + angle : angle;
        return angle;
    }

    /**获取两点的距离 */
    static getDis(pos1: Vec2, pos2: Vec3 | Vec2): number {
        return Math.sqrt((pos2.x - pos1.x) * (pos2.x - pos1.x) + (pos2.y - pos1.y) * (pos2.y - pos1.y))
    }
}